package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduTalent.*;
import com.jwsoft.manager.core.integration.EduTalentIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 人才子女审核网关
 *
 * @author hhj
 * @since 2023-04-26
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "人才子女审核", description = "人才子女审核")
public class EduTalentController {

    @Autowired
    public EduTalentIntegration eduTalentIntegration;

    @Operation(summary = "人才子女审核分页查询",description = "人才子女审核分页查询")
    @PostMapping(value = "/eduTalent0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduTalentVO>> getList(@RequestBody @Validated EduTalentQueryVO vo) {
        return AppResponse.successData(eduTalentIntegration.getList(vo));
    }

    @Operation(summary = "人才子女审核根据主键查询详情",description = "人才子女审核根据主键查询详情")
    @PostMapping(value = "/eduTalent0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentVO> getById(@RequestBody @Validated EduTalentKeyVO vo) {
        return AppResponse.successData(eduTalentIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女审核新增",description = "人才子女审核新增")
    @PostMapping(value = "/eduTalent0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduTalentVO vo) {
        return AppResponse.successData(eduTalentIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女审核修改",description = "人才子女审核修改")
    @PostMapping(value = "/eduTalent0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduTalentVO vo) {
        return AppResponse.successData(eduTalentIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女审核删除",description = "人才子女审核删除")
    @PostMapping(value = "/eduTalent0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduTalentKeyVO vo) {
        eduTalentIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女信息审核",description = "人才子女信息审核")
    @PostMapping(value = "/eduTalent0007", produces = "application/json;charset=UTF-8")
    public AppResponse auditEduTalent(@RequestBody @Validated EduTalentAuditVO vo) {
        eduTalentIntegration.auditEduTalent(vo);
        return AppResponse.successMsg("审核成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女信息退回到待审核",description = "人才子女信息退回到待审核")
    @PostMapping(value = "/eduTalent0008", produces = "application/json;charset=UTF-8")
    public AppResponse returnAuditEduTalent(@RequestBody @Validated EduTalentAuditVO vo) {
        eduTalentIntegration.returnAuditEduTalent(vo);
        return AppResponse.successMsg("退回到待审核成功！");
    }
    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "家长端人才子女就读申请提交",description = "家长端人才子女就读申请提交")
    @PostMapping(value = "/eduTalent0009", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentVO> addApp(@RequestBody @Validated(value = {Validators.Add.class}) EduTalentVO vo) {
        return AppResponse.successData(eduTalentIntegration.addApp(vo));
    }
    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "管理端解锁人才子女申请锁定",description = "管理端解锁人才子女申请锁定")
    @PostMapping(value = "/eduTalent0010", produces = "application/json;charset=UTF-8")
    public AppResponse unLock(@RequestBody @Validated EduTalentKeyVO vo) {
        eduTalentIntegration.unLock(vo);
        return AppResponse.successMsg("解锁成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才子女分配学校",description = "人才子女分配学校")
    @PostMapping(value = "/eduTalent0011", produces = "application/json;charset=UTF-8")
    public AppResponse assignEduTalent(@RequestBody @Validated EduTalentAssignVO vo) {
        eduTalentIntegration.assignEduTalent(vo);
        return AppResponse.successMsg("分配学校成功！");
    }

    @RequestMapping(
            value = "/eduTalent0012",
            method = {RequestMethod.POST, RequestMethod.GET})
    @Operation(summary = "人才子女信息导出", description = "人才子女信息导出")
    @NoSignCrypto
    public void downloadData(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) EduTalentQueryVO vo,
            HttpServletResponse response) {

        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduTalentIntegration.downloadData(vo,response);

    }
}
